<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>税开管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="splBullMsgInfo_form">
    <div class="fieldset1 tabel_col tabel_col_s clearFix">

        <div class="fieldBox col_50">
            <div class="label">企业名称</div>
            <div class="field">
                <input name="rcCstCorpBscInfoId" id="rcCstCorpBscInfoId" type="hidden" value="${rcWlTpMgtVO.rcCstCorpBscInfoId}">
                <input name="isValid" id="isValid" type="hidden" value="${rcWlTpMgtVO.isValid}">
                <span id="corpCstNm" name="corpCstNm">&nbsp;</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">操作人</div>
            <div class="field">
                <span id="operationNm" name="operationNm">&nbsp;</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">证件类型</div>
            <div class="field">
                <span id="corpCertTypCdNm" name="corpCertTypCdNm">&nbsp;</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">证件号码</div>
            <div class="field">
                <span id="corpCertNo" name="corpCertNo">&nbsp;</span>
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">第1-12月增值税开票总收入</div>
            <div class="field">
                <input name="invoiTotalReve1to12" id="invoiTotalReve1to12" onchange="parseNumber()" type="text" class="ui-textbox" value="${rcWlTpMgtVO.invoiTotalReve1to12}" validate="{number:true,maxlength:30}">
            </div>
        </div>
        <div class="fieldBox col_50">
            <div class="label">第13-24月增值税开票总收入</div>
            <div class="field">
                <input name="invoiTotalReve1to24" id="invoiTotalReve1to24" onchange="parseNumber1()" type="text"  class="ui-textbox" value="${rcWlTpMgtVO.invoiTotalReve1to24}" validate="{number:true,maxlength:30}">
            </div>
        </div>

        <div class="fieldBox col_50">
            <div class="label">企业级别</div>
            <div class="field" style="width: 100%;">
                <span id="enterpriseLevel" name="enterpriseLevel"></span>
                <%--<select name="enterpriseLevel" id="enterpriseLevel" ligerui="width: 160">--%>
                    <%--<option value=" "  selected="selected">请选择</option>--%>
                    <%--<option value="1" >1</option>--%>
                    <%--<option value="2">2</option>--%>
                    <%--<option value="3">3</option>--%>
                    <%--<option value="4">4</option>--%>
                    <%--<option value="5">5</option>--%>
                <%--</select>--%>
            </div>
        </div>

        <div class="fieldBox col_100">
            <div class="label">备注</div>
            <div class="field" style="width: 100%;">
                <textarea name="rem" id="rem" rows="4" class="l-textarea" style="width:93%">${rcWlTpMgtVO.rem}</textarea>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">税报附件</div>
            <div class="field" style="width: 100%;">
                <c:if test="${not empty sysUlFilesRecVO1.filePath}">
                    <a href="javascript:uploadFileByUrl('${sysUlFilesRecVO1.filePath}', '${sysUlFilesRecVO1.filePath}')">${sysUlFilesRecVO1.fileNm}</a>&nbsp;&nbsp;&nbsp;
                </c:if>
                <c:if test="${empty sysUlFilesRecVO1.filePath}">
                    <span class="padding_top_style2" style="color:orangered;">税报1照片不存在</span>&nbsp;&nbsp;&nbsp;
                </c:if>
                <c:if test="${not empty sysUlFilesRecVO2.filePath}">
                    <a href="javascript:uploadFileByUrl('${sysUlFilesRecVO2.filePath}', '${sysUlFilesRecVO2.filePath}')">${sysUlFilesRecVO2.fileNm}</a>&nbsp;&nbsp;&nbsp;
                </c:if>
                <c:if test="${empty sysUlFilesRecVO2.filePath}">
                    <span class="padding_top_style2" style="color:orangered;">税报2照片不存在</span>&nbsp;&nbsp;&nbsp;
                </c:if>
                <c:if test="${not empty sysUlFilesRecVO3.filePath}">
                    <a href="javascript:uploadFileByUrl('${sysUlFilesRecVO3.filePath}', '${sysUlFilesRecVO3.filePath}')">${sysUlFilesRecVO3.fileNm}</a>
                </c:if>
                <c:if test="${empty sysUlFilesRecVO3.filePath}">
                    <span class="padding_top_style2" style="color:orangered;">税报3照片不存在</span>
                </c:if>
            </div>
        </div>
    </div>

    <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
        <div class="fieldBox col_100">
            <div class="label" style="height: auto">
                <span id="authBtn" class="sq-button sq-button-hasicon">获取三方数据</br>(剩余次数:${rcWlTpMgtVO.authCount})</span></br>
            </div>
            <div class="field" style="width: 100%;line-height: 35px;">
                <span id="authThreeDataDesc">
                    <c:if test="${rcWlTpMgtVO.authStsCd eq '1'}">获取失败,稍后请重新获取</c:if>
                    <c:if test="${rcWlTpMgtVO.authStsCd eq '2'}">三方数据已成功获取</c:if>
                    <c:if test="${rcWlTpMgtVO.authStsCd eq '3'}">无法获取,请手动补充数据</c:if>
                </span>
            </div>
        </div>
    </div>
    <div id="stand" class="fieldBox col_100">
        <div class="label"></div>
        <div class="field" style="text-align: center">
            <span name="" id="">&nbsp;</span>
        </div>
    </div>

    <div class="sqPanel">
        <div class="sqPanel_head inL">
            <span>证明文件</span>
        </div>
        <table class="table_full tbl_1">
            <tbody>
            <tr>
                <c:forEach items="${dtlList}" var="cstFile" varStatus="status">
                <c:if test="${status.index%4==0}">
            </tr>
            <tr>
                </c:if>
                <td>
                    <h5>${cstFile.datNm}</h5>
                    <div class="imgBox">
                        <c:if test="${ empty cstFile.filePath}">
                            <img src="${defImg}"  onclick="showImg(event);" fileId="">
                        </c:if>
                        <c:if test="${ not empty cstFile.filePath}">
                            <img id="imgPath" src="${cstFile.filePath}" onclick="showImg(event);" href="${cstFile.filePath}" fileId="">
                        </c:if>
                            <%-- <img src="${cstFile.fileRec.filePath}"> --%>
                    </div>
                    <div class="btns">
                        <span class="sq-button sq-button-round co_normal"  sysCd="${cstFile.sysCd}" orgCd="${cstFile.orgCd}" cfgCd="${cstFile.cfgCd}" cfgDtlCd="${cstFile.cfgDtlCd}" <%-- cfgDtId="${cstFile.cfgDtId}"  --%> onclick="uploadFile(this,'${cstFile.sysCd}','${cstFile.orgCd}','${cstFile.cfgCd}','${cstFile.cfgDtlCd}')">上传</span>
                    </div>
                </td>
                </c:forEach>
            </tr>
            </tbody>
        </table>

    </div>
    <div id="noticeDIV1" class="fieldBox col_100">
        <div class="label"></div>
        <div class="field" style="text-align: center">
            <span name="" id="">第1个月-第12个月的增值税开票总收入</span>
        </div>
    </div>
    <div id="noticeDIV2" class="fieldBox col_100">
        <div class="label"></div>
        <div class="field" style="text-align: center">
            <span name="" id="">第13个月-第24个月的增值税开票总收入</span>
        </div>
    </div>
    <%--<div id="noticeDIV3" class="fieldBox col_100">--%>
        <%--<div class="label"></div>--%>
        <%--<div class="field" style="text-align: center">--%>
            <%--<span name="" id="">企业级别</span>--%>
        <%--</div>--%>
    <%--</div>--%>
    <div id="noticeDIV4" class="fieldBox col_100">
        <div class="label"></div>
        <div class="field" style="text-align: center">
            <span name="" id="" style="color: red;">二者必须有其一</span>
        </div>
    </div>

    <div class="btnsBox">
        <div id="noticeDIV" class="fieldBox col_100">
            <div class="label"></div>
            <div class="field" style="text-align: center;margin-top: 30px;">
                <span name="" id="" style="color: red;">提交后数据将无法修改，请确认检查无误后提交</span>
            </div>
        </div>
        <%--<span id="saveRcWlTpMgt_Btn" class="sq-button sq-button-round l-dialog-btn-ok">保存</span>--%>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>
</form>
<script>
    var rcWlTpMgtId = "${rcWlTpMgtVO.id}";//主键ID
    var corpCstNm = "${rcWlTpMgtVO.corpCstNm}";
    var operationNm = "${rcWlTpMgtVO.operationNm}";
    var corpCertTypCdNm = "${rcWlTpMgtVO.corpCertTypCdNm}";
    var corpCertNo = "${rcWlTpMgtVO.corpCertNo}";
    $(function() {
        var invoiTotalReve1to12;
        var invoiTotalReve1to24;
        $("#splBullMsgInfo_form").ligerForm({
            validate: true
        });
        $("#corpCstNm").html(corpCstNm);
        $("#operationNm").html(operationNm);
        $("#corpCertTypCdNm").html(corpCertTypCdNm);
        $("#corpCertNo").html(corpCertNo);
        $("#authBtn").bind("click",function(){
            authThreeData();
        });
    });

    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            //SQ.imgPreview(_url);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }

    function parseNumber() {
        invoiTotalReve1to12 = $("#invoiTotalReve1to12").val();
        $("#invoiTotalReve1to12").val(currencyFormatter(invoiTotalReve1to12, 2));
    }

    function parseNumber1() {
        invoiTotalReve1to24 = $("#invoiTotalReve1to24").val();
        $("#invoiTotalReve1to24").val(currencyFormatter(invoiTotalReve1to24, 2));
    }

    function currencyFormatter(num, precision) {
        var cents, sign;
        if (!num) num = 0;
        num = num.toString().replace(/\$|\,/g, '').replace(/[a-zA-Z]+/g, '');
        if (num.indexOf('.') > -1) num = num.replace(/[0]+$/g, '');
        if (isNaN(num))
            num = 0;
        sign = (num == (num = Math.abs(num)));

        if (precision == null)
        {
            num = num.toString();
            cents = num.indexOf('.') != -1 ? num.substr(num.indexOf('.') + 1) : '';
            if (cents)
            {
                num = Math.floor(num * 1);
                num = num.toString();
            }
        }
        else
        {
            precision = parseInt(precision);
            var r = Math.pow(10, precision);
            num = Math.floor(num * r + 0.50000000001);
            cents = num % 100;
            num = Math.floor(num / r).toString();
            while (cents.toString().length < precision)
            {
                cents = "0" + cents;
            }
        }
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3) ; i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
                num.substring(num.length - (4 * i + 3));
        var numStr = "" + (((sign) ? '' : '-') + '' + num);
        if (cents) numStr += ('.' + cents);
        return numStr;
    }

    function authThreeData(){
        var logs = "确认获取三方数据吗?若获取成功此页面将关闭,请知悉！";
        $.ligerDialog.confirm(logs, function (flag) {
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data : {
                    "rcCstCorpBscInfoId" : $("#rcCstCorpBscInfoId").val(),
                    "rcWlTpMgtId" : rcWlTpMgtId
                },
                url: "<%=path%>/corp/rcwltpmgt/authThreeData.do",
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        parent.$("#clearBtn").click();
                        parent.$("#searchBtn").click();
                        frameElement.dialog.close();
                        // setInterval('Remove_navTab();callback();',1000);
                    } else {
                        $("#authThreeDataDesc").html(msg.info);
                        if (msg.data != null) {
                            $("#authBtn").html('获取三方数据</br>(剩余次数:' + msg.data.authCount + ')');
                        }
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    // 保存
    frameElement.dialog.onOk = function () {
        saveVlVectorInfo();
    }
    // 取消
    frameElement.dialog.onCancel = function () {
        frameElement.dialog.close();
    }

    // 保存
    function saveVlVectorInfo(){
        var form = liger.get("splBullMsgInfo_form");
        if (!form.valid()) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }

        if($("#invoiTotalReve1to12").val() == "" && $("#invoiTotalReve1to24").val() == ""){
            UIUtils.alertWarning("总收入不能都为空!");
            return;
        }

        var data = form.getData();
        data["rcCstCorpBscInfoId"] = $("#rcCstCorpBscInfoId").val();
        data["invoiTotalReve1to12"] = $("#invoiTotalReve1to12").ligerGetTextBoxManager().getValue();
        data["invoiTotalReve1to24"] = $("#invoiTotalReve1to24").ligerGetTextBoxManager().getValue();
        data["isValid"] = $("#isValid").val();
        $.ligerDialog.hide();
        var _url;
        <%--if (splBullMsgInfoId == '') {//新增--%>
        <%--_url = '<%=path%>/splmsg/splBullMsgInfo/add.do';--%>
        <%--} else {//修改--%>
        _url = '<%=path%>/corp/rcwltpmgt/modify.do?id=' + rcWlTpMgtId;
        // }
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: _url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    parent.$("#clearBtn").click();
                    parent.$("#searchBtn").click();
                    frameElement.dialog.close();
                    // setInterval('Remove_navTab();callback();',1000);
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function uploadFile(imgObj,sysCd,orgCd,cfgCd,cfgDtlCd){
        var obj = $(imgObj).parent().parent().find("img")
        var  url = '<%=path%>/corp/rcwltpmgt/addInvestImgPage.do?sysCd='+sysCd+'&&orgCd='+orgCd+'&&cfgCd='+cfgCd+'&&cfgDtlCd='+cfgDtlCd+'&&rcWlTpMgtId='+rcWlTpMgtId;
        $.ligerDialog.open({
            height:300,
            width: 600,
            title : '上传图片',
            url: url,
            // showMax: false,
            // showToggle: true,
            // showMin: false,
            // isResize: true,
            // slide: false,
            data: {
                imgObj: obj
            }
        });

    }

    function showImg(e){
        /* 		 e.preventDefault();
              var href = $(e.target).attr('href');
              if(!href){
                  return;
              }
              if(SQ.regs.img.test(href)){
                  SQ.imgPreview(href);
              } */
        e.preventDefault();
        var href = $(e.target).attr('src');
        if(!href){
            return;
        }
        if(SQ.regs.img.test(href)){
            var imgSrc = $(e.target).attr('src'),
                imgTit = $(e.target).attr('title');
            window.__ImgSrc = imgSrc;
            window.__ImgTit = imgTit;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }
    }
</script>
</body>
</html>
